home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWTrackr.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  9.9 KB  |  322 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWTrackr.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWTRACKR_H
  13. #include "FWTrackr.h"
  14. #endif
  15.  
  16. #ifndef FWUTIL_H
  17. #include "FWUtil.h"
  18. #endif
  19.  
  20. #ifndef FWVIEW_H
  21. #include "FWView.h"
  22. #endif
  23.  
  24. #ifndef FWFRAME_H
  25. #include "FWFrame.h"
  26. #endif
  27.  
  28. #ifndef FWPART_H
  29. #include "FWPart.h"
  30. #endif
  31.  
  32. // ----- OS Includes -----
  33.  
  34. #ifndef FWRECT_H
  35. #include "FWRect.h"
  36. #endif
  37.  
  38. #ifndef FWEVENT_H
  39. #include "FWEvent.h"
  40. #endif
  41.  
  42. #ifndef FWEVENTU_H
  43. #include "FWEventU.h"
  44. #endif
  45.  
  46. #ifndef FWACQUIR_H
  47. #include "FWAcquir.h"
  48. #endif
  49.  
  50. // ----- Foundation Includes -----
  51.  
  52. #ifndef FWDEBUG_H
  53. #include "FWDebug.h"
  54. #endif
  55.  
  56. // ----- OpenDoc Includes -----
  57.  
  58. #ifndef SOM_ODTransform_xh
  59. #include <Trnsform.xh>
  60. #endif
  61.  
  62. #ifndef SOM_ODFacet_xh
  63. #include <Facet.xh>
  64. #endif
  65.  
  66. #ifndef SOM_ODFrame_xh
  67. #include <Frame.xh>
  68. #endif
  69.  
  70. #ifndef SOM_ODSession_xh
  71. #include <ODSessn.xh>
  72. #endif
  73.  
  74. #ifndef SOM_ODDragAndDrop_xh
  75. #include <DragDrp.xh>
  76. #endif
  77.  
  78. //========================================================================================
  79. //    Runtime Info
  80. //========================================================================================
  81.  
  82. #if FW_LIB_EXPORT_PRAGMAS
  83. #pragma lib_export on
  84. #endif
  85.  
  86. #ifdef FW_BUILD_MAC
  87. #pragma segment framework
  88. #endif
  89.  
  90. //========================================================================================
  91. //    class FW_CBaseTracker
  92. //========================================================================================
  93.  
  94. //----------------------------------------------------------------------------------------
  95. //    FW_CBaseTracker::FW_CBaseTracker
  96. //----------------------------------------------------------------------------------------
  97.  
  98. FW_CBaseTracker::FW_CBaseTracker(Environment *ev, FW_CView* view, ODFacet* facet) :
  99.     fFacet(facet),
  100.     fView(view)
  101. {
  102. }
  103.  
  104. //----------------------------------------------------------------------------------------
  105. //    FW_CBaseTracker::~FW_CBaseTracker
  106. //----------------------------------------------------------------------------------------
  107.  
  108. FW_CBaseTracker::~FW_CBaseTracker()
  109. {
  110. }
  111.  
  112. //========================================================================================
  113. //    class FW_CDropTracker
  114. //========================================================================================
  115.  
  116. //----------------------------------------------------------------------------------------
  117. //    FW_CDropTracker::FW_CDropTracker
  118. //----------------------------------------------------------------------------------------
  119.  
  120. FW_CDropTracker::FW_CDropTracker(Environment *ev, FW_CView* view, ODFacet* facet) :
  121.     FW_CBaseTracker(ev, view, facet)
  122. #ifdef FW_BUILD_MAC
  123.     ,fMacHiliteOn(FALSE)
  124. #endif
  125. {
  126.     fSession = view->GetFrame(ev)->GetPart(ev)->GetSession(ev);
  127. }
  128.  
  129. //----------------------------------------------------------------------------------------
  130. //    FW_CDropTracker::~FW_CDropTracker
  131. //----------------------------------------------------------------------------------------
  132.  
  133. FW_CDropTracker::~FW_CDropTracker()
  134. {
  135. }
  136.  
  137. //----------------------------------------------------------------------------------------
  138. //    FW_CDropTracker::HandleBeginTracking
  139. //----------------------------------------------------------------------------------------
  140. //    where is in frame coordinate
  141.  
  142. void FW_CDropTracker::HandleBeginTracking(Environment *ev, const FW_CPoint& where, unsigned long dragAttributes)
  143. {        
  144.     fDragAttributes = dragAttributes;
  145.     
  146.     FW_CAcquiredODTransform aqInternalTransform = GetFacet(ev)->GetFrame(ev)->AcquireInternalTransform(ev, NULL);
  147.     FW_CPoint anchorPoint = where.InverseTransformCopy(ev, aqInternalTransform);
  148.     fAnchorPoint = this->BeginTracking(ev, anchorPoint);
  149. }
  150.  
  151. //----------------------------------------------------------------------------------------
  152. //    FW_CDropTracker::HandleContinueTracking
  153. //----------------------------------------------------------------------------------------
  154. //    where is in frame coordinate
  155.  
  156. void FW_CDropTracker::HandleContinueTracking(Environment *ev, const FW_CPoint& where)
  157. {
  158.     FW_CAcquiredODTransform aqInternalTransform = GetFacet(ev)->GetFrame(ev)->AcquireInternalTransform(ev, NULL);
  159.     FW_CPoint currentPoint = where.InverseTransformCopy(ev, aqInternalTransform);
  160.     fPreviousPoint = this->ContinueTracking(ev, fAnchorPoint, fPreviousPoint, currentPoint);
  161. }
  162.  
  163. //----------------------------------------------------------------------------------------
  164. //    FW_CDropTracker::HandleEndTracking
  165. //----------------------------------------------------------------------------------------
  166. //    where is in frame coordinate
  167.  
  168. FW_Boolean FW_CDropTracker::HandleEndTracking(Environment *ev, const FW_CPoint& where)
  169. {
  170.     FW_CAcquiredODTransform aqInternalTransform = GetFacet(ev)->GetFrame(ev)->AcquireInternalTransform(ev, NULL);
  171.     FW_CPoint currentPoint = where.InverseTransformCopy(ev, aqInternalTransform);
  172.     return this->EndTracking(ev, fAnchorPoint, currentPoint);
  173. }
  174.  
  175. //----------------------------------------------------------------------------------------
  176. //    FW_CDropTracker::BeginTracking
  177. //----------------------------------------------------------------------------------------
  178.  
  179. FW_CPoint FW_CDropTracker::BeginTracking(Environment* ev, const FW_CPoint& anchorPoint)
  180. {
  181.     if (!IsInSourceFrame(ev))
  182.     {
  183.         FW_CAcquiredODShape aqHiliteShape = GetView(ev)->GetFrame(ev)->AcquireDragHiliteShape(ev, GetFacet(ev));
  184.         this->ShowDragHilite(ev, aqHiliteShape, TRUE);
  185.     }
  186.     
  187.     return anchorPoint;
  188. }
  189.  
  190. //----------------------------------------------------------------------------------------
  191. //    FW_CDropTracker::BeginTracking
  192. //----------------------------------------------------------------------------------------
  193.  
  194. FW_CPoint FW_CDropTracker::ContinueTracking(Environment* ev,
  195.                                             const FW_CPoint& anchorPoint, 
  196.                                             const FW_CPoint& previousPoint, 
  197.                                             const FW_CPoint& currentPoint)
  198. {
  199.     return currentPoint;
  200. }
  201.  
  202. //----------------------------------------------------------------------------------------
  203. //    FW_CDropTracker::EndTracking
  204. //----------------------------------------------------------------------------------------
  205.  
  206. FW_Boolean FW_CDropTracker::EndTracking(Environment* ev,
  207.                                         const FW_CPoint& anchorPoint, 
  208.                                         const FW_CPoint& lastPoint)
  209. {
  210.     this->HideDragHilite(ev);    
  211.     return anchorPoint != lastPoint;
  212. }
  213.  
  214. //----------------------------------------------------------------------------------------
  215. //    FW_CDropTracker::ShowDragHilite
  216. //----------------------------------------------------------------------------------------
  217. // hiliteShape is in frame coordinate
  218.  
  219. void FW_CDropTracker::ShowDragHilite(Environment* ev, ODShape* hiliteShape, FW_Boolean showInside)
  220. {    
  221. #ifdef FW_BUILD_MAC
  222.     FW_ASSERT(fMacHiliteOn == FALSE);
  223.     FW_ASSERT(hiliteShape);
  224.     
  225.     ODFacet* facet = GetFacet(ev);
  226.     FW_CFrame* frame = GetView(ev)->GetFrame(ev);
  227.     FW_ASSERT(facet->GetFrame(ev) == frame->GetODFrame(ev));    //just to be sure
  228.  
  229.     FW_CWindowContext gc(ev, facet);        // focus drawing to the window
  230.  
  231.     FW_CAcquiredODShape aqHiliteShape = hiliteShape->Copy(ev);
  232.     FW_CAcquiredODTransform aqWindowFrameXForm = GetFacet(ev)->AcquireWindowFrameTransform(ev, NULL);
  233.     aqHiliteShape->Transform(ev, aqWindowFrameXForm);
  234.  
  235.     ::ShowDragHilite(fSession->GetDragAndDrop(ev)->GetDragReference(ev), 
  236.                      aqHiliteShape->GetQDRegion(ev), 
  237.                      showInside);
  238.     fMacHiliteOn = TRUE;
  239. #endif
  240. }
  241.  
  242. //----------------------------------------------------------------------------------------
  243. //    FW_CDropTracker::HideDragHilite
  244. //----------------------------------------------------------------------------------------
  245.  
  246. void FW_CDropTracker::HideDragHilite(Environment* ev)
  247. {
  248. #ifdef FW_BUILD_MAC
  249.     if (fMacHiliteOn)
  250.     {
  251.         FW_CWindowContext gc(ev, GetFacet(ev));        // focus drawing to the window
  252.         ::HideDragHilite(fSession->GetDragAndDrop(ev)->GetDragReference(ev));
  253.         
  254.         fMacHiliteOn = FALSE;
  255.     }
  256. #endif
  257. }
  258.  
  259. //========================================================================================
  260. //    class FW_CTracker
  261. //========================================================================================
  262.  
  263. //----------------------------------------------------------------------------------------
  264. //    FW_CTracker::FW_CTracker
  265. //----------------------------------------------------------------------------------------
  266.  
  267. FW_CTracker::FW_CTracker(Environment *ev, FW_CView* view, ODFacet* facet, FW_Boolean waitMouseMoved) :
  268.     FW_CBaseTracker(ev, view, facet),
  269.     fWaitMouseMoved(waitMouseMoved)
  270. {
  271. }
  272.  
  273. //----------------------------------------------------------------------------------------
  274. //    FW_CTracker::~FW_CTracker
  275. //----------------------------------------------------------------------------------------
  276.  
  277. FW_CTracker::~FW_CTracker()
  278. {
  279. }
  280.  
  281. //----------------------------------------------------------------------------------------
  282. //     FW_CTracker::Track
  283. //----------------------------------------------------------------------------------------
  284.  
  285. FW_Boolean FW_CTracker::Track(Environment *ev, const FW_CMouseEvent& theMouseEvent)
  286. {
  287.     FW_ASSERT(GetFacet(ev) != NULL);
  288.     FW_ASSERT(GetView(ev) != NULL);
  289.  
  290.     // ----- Flush update event pending for this window
  291.     FW_CAcquiredODWindow aqWindow = GetFacet(ev)->GetFrame(ev)->AcquireWindow(ev);
  292.     aqWindow->Update(ev);
  293.     
  294.     if (fWaitMouseMoved && !theMouseEvent.WaitUntilMouseMoved(ev))
  295.         return FALSE;
  296.     
  297.     FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  298.     FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, GetFacet(ev)->GetFrame(ev));
  299.     frame->GetContentView(ev)->FrameToViewContent(ev, where);
  300.  
  301.     fAnchorPoint = BeginTracking(ev, where);
  302.     
  303.     FW_CPoint currentLoc;
  304.     fPreviousPoint = fAnchorPoint;
  305.     
  306.     do  
  307.     {
  308.         FW_CAcquiredODWindow aqODWindow = GetFacet(ev)->GetFrame(ev)->AcquireWindow(ev);
  309.         
  310.         {
  311.             FW_CViewContext vc(ev,GetView(ev), GetFacet(ev));
  312.             currentLoc = ::FW_GetMouseLocation(aqODWindow, vc);
  313.         }
  314.         
  315.         fPreviousPoint = ContinueTracking(ev, fAnchorPoint, fPreviousPoint, currentLoc);
  316.     } 
  317.     while (FW_WaitMouseUp());
  318.     
  319.     return EndTracking(ev, fAnchorPoint, currentLoc);
  320. }
  321.  
  322.